<?php
require_once __DIR__."/../usr/share/locale/priority_exception/es.php";

class Priority_Exception extends Exception{
	
    protected $message;

    protected $code;

    protected $file;

    protected $line;
    
    private $default_locale = "es";
    
    private $default_msg;
    
    private $locale_msg;
    
    const LOCALE_NULL = null;
    
    private $construct_returned;
    
    function __construct($message, $code = 0, Exception $previus = NULL, $priority = 0, $locale = "es"){
    	
    	$namespace_default_locale = "\\exception\\".$this->default_locale."\\Locale_Priority_Exception";
    	
    	$this->default_msg = $namespace_default_locale::$msg;
    	
    	$set_locale_returned = $this->set_locale($locale);
    	
    	$this->message = $this->locale_msg[$code] ?: $this->default_msg[$code] ?: $message;

        $this->code = $code;
        
        $priority_returned = $this->priority($priority);
        
        $this->construct_returned = array(
	        "external_locale" => $set_locale_returned,
        	"priority"=>$priority_returned
        );
        
    }
    
    public function get_construct_returned(){
    	
    	return $this->construct_returned;
    	
    }
    private function set_locale($locale){
    	
    	$locale_path = __DIR__."/../usr/share/locale/priority_exception";
    	
    	$this->locale_msg = self::LOCALE_NULL;
    	
    	$is_included = false;
    	
    	if($locale != $this->default_locale && file_exists( $file = $locale_path."/".$locale.".php") ){
    		
    		include_once $file;
    		
    		$namespace_locale = "\\exception\\".$locale."\\Locale_Priority_Exception";
    		
    		$this->locale_msg = $namespace_locale::$msg;
    		
    		$is_included = true;
    	}
    	
    	return array("$locale"=> $is_included);
    }
    private function priority($priority = 0){
    	
    	$error = NULL;
    	$mail = NULL;
    	
    	switch ($priority) {
    		case 1:
    			$error = $this->error_log();
    			break;
    			
    		case 2:
    			$error = $this->error_log();
    			$mail = $this->send_mail();
    			break;
    		/*
    		default:
    			$error = NULL;
    			$mail = NULL;
    			break;
    		//*/
    	}
    	return array("level"=>$priority,"error_log"=>$error,"mail"=>$mail);
    }
    
    private function error_log(){

    	//echo "crea archivo de error\n";
    	
    	return true;
    }
    
    private function send_mail(){
    	
    	//echo "envia un mail\n";
    	
    	return true;
    }
}
?>